import {getGpsToken} from "@/api/system/user";

const externalInterface = {
  state: {
    x_token: null,
    member_id: null,
    url: null
  },

  mutations: {
    SET_WX_TOKEN: (state, token) => {
      state.x_token = token
    },
    SET_WX_MEMBER_ID: (state, member_id) => {
      state.member_id = member_id
    },
    SET_WX_URL: (state, url) => {
      state.url = url
    }
  },

  actions: {
    // 登录
    LoginWX({commit}) {
      return new Promise((resolve, reject) => {
        getGpsToken().then(res => {
          if (res.code == 200) {
            commit('SET_WX_TOKEN', res.x_token)
            commit('SET_WX_MEMBER_ID', res.member_id)
            commit('SET_WX_URL', res.url)
            resolve({
              x_token: res.x_token,
              member_id: res.member_id
            })
          }
        }).catch(res => {
          reject(res)
        })
      })
    },

  }
}

export default externalInterface
